package com.fhz.kotlintest.databinding.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

/**
 * 时间:2022/1/5
 * @author msfeng
 * 简述: TODO
 */
abstract class BaseVMFragment<V:ViewDataBinding,VM:ViewModel> : BaseViewFragment<V>() {

    protected lateinit var viewModel: VM
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        //创建viewModel
        initViewModel()
        //观察数据更新变化
        observableData()
        //设置view
        initView()
        //设置事件
        initEvent()
        //开始加载数据
        startLoadData()
    }

    open fun initView(){

    }

    open fun startLoadData(){

    }
    open fun initEvent(){

    }

    open fun observableData(){

    }

    private fun initViewModel(){
       viewModel =  ViewModelProvider(this).get(getVMClass())
    }

    abstract fun getVMClass():Class<VM>

}